//-----------------------------------------------------------------------------------
#include "StarNode.h"
//-----------------------------------------------------------------------------------
StarNode::StarNode()
:
m_npParent(NULL),
m_iCost(0),
m_iType(0),
m_iDistance(0)
{
	m_sPosition.m_isRow = 0;
	m_sPosition.m_isCol = 0;
}
//-----------------------------------------------------------------------------------
StarNode::StarNode( int iRow, 
					int iCol, 
					int iType, 
					int iCost, 
					StarNode *npParent )
:
m_iCost(iCost),
m_iType(iType),
m_npParent(npParent)
{
	m_sPosition.m_isRow = iRow;
	m_sPosition.m_isCol = iCol;

	if( m_npParent )
	{
		m_iDistance = m_npParent->m_iDistance + m_iCost;
	}
	else
	{
		m_iDistance = m_iCost;
	}

	m_pkShape = new zak::Shape();
	m_pkShape->SetShape(zak::ZAK_SHAPE_QUAD);
	m_pkShape->SetDim(20,20);

	if (m_iType == TYPE_WALL)
	{
		m_pkShape->SetColor(0xFFFF0000);
	}
	else if(m_iType == TYPE_NORM)
	{
		m_pkShape->SetColor(0xFF000000);
	}
	else
	{
		m_pkShape->SetColor(0xFFFF00FF);
	}

	m_pkShape->SetPos(((m_sPosition.m_isRow * m_pkShape->GetWidth() + 2) * 1 - 400),
					 -((m_sPosition.m_isCol * m_pkShape->GetHeight() + 2) * 1 + 300));
}
//-----------------------------------------------------------------------------------
StarNode::~StarNode()
{

}
//-----------------------------------------------------------------------------------
StarNode * StarNode::GetParent()
{
	return m_npParent;
}
//-----------------------------------------------------------------------------------
sPosition ** StarNode::NormalizePath()
{
	StarNode * npStarNode = this;
	std::vector<sPosition*> vecPosition;
	sPosition ** arrPosition;

	vecPosition.push_back( NULL );

	while( npStarNode )
	{
		vecPosition.push_back( &npStarNode->m_sPosition );
		npStarNode->m_pkShape->SetColor(0xFF00FF00);
		npStarNode = npStarNode->GetParent();
	}

	int arrPosMax = (int)vecPosition.size();
	arrPosition = new sPosition*[arrPosMax];

	for( int i = 0; i < arrPosMax; i++ )
	{
		arrPosition[i] = vecPosition.back();
		vecPosition.pop_back();
	}

	return arrPosition;
}
//-----------------------------------------------------------------------------------
void StarNode::DrawShape()
{
	m_pkShape->Draw();
}
//-----------------------------------------------------------------------------------